/*********************************************************************\
*
*                  (c) lkc
*                  All Rights Reserved. lkc Confidential
*
\*********************************************************************/
/*********************************************************************\
*   Title                      :
*
*   Module Description         :
*
*   Author                     : lkc
*
*   Created                    : 2018-7-24
*
\*********************************************************************/

#include <QDebug>
#include "ProtocolBasePosix.h"
#include <thread>

int ProtocolBasePosix::GetFd()
{
    if(!GetCommTool())
    {
        qDebug()<<"GetFd() m_commTool==nullptr";
        return -1;
    }
    return GetCommTool()->GetFd();
}

void ProtocolBasePosix::CycleSendThread()
{
    if(GetCycleTimeMS()<=0)//默认周期发送时间为0，周期发送线程不做任何操作
    {
        return;
    }
    printf("fd is %d and cycle time is %dms\n",GetFd(),GetCycleTimeMS());
    std::thread([&]()
    {
        while(true)
        {
            if(CycleSendOnce() <0)
            {
                printf("send data failed!\n");
                std::this_thread::sleep_for(std::chrono::milliseconds(2000));
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(GetCycleTimeMS()));
        }
    }).detach();
}

/********************************************************************\
 *
 * REVISION RECORDS
 *
\*********************************************************************/
/*********************************************************************/
/*
 *
 *
 *
\*********************************************************************/
/*------------------------------The End------------------------------*/
